package cn.bellychang.leetcode.question226;

/**
 * @author ChangLiang
 * @date 2021/2/8
 */
public class Solution {

    public TreeNode invertTree(TreeNode root) {

        return invert(root);
    }

    public TreeNode invert(TreeNode treeNode) {
        if (treeNode == null) {
            return null;
        }
        if (treeNode.left == null && treeNode.right == null) {
            return treeNode;
        }
        TreeNode temp = treeNode.left;
        treeNode.left = invert(treeNode.right);
        treeNode.right = invert(temp);
        return treeNode;
    }
}
